/**
 * 
 */
package org.jenkon.assertion;

/**
 * class with assertion methods for strings.
 * 
 * @author jkonopka
 * 
 */
public final class StringAssert {

	/**
	 * hide this public constructor for this util class.
	 */
	private StringAssert() {
	}

	/**
	 * check the {@link String} of is empty. if the {@link String} is not empty, then <code>throw new {@link IllegalArgumentException}</code> with the
	 * message 'the text is not empty'.
	 * 
	 * @see #isEmpty(String, String)
	 * @param text the {@link String} to check of is empty
	 * @throws IllegalArgumentException if the {@link String} is not empty
	 * @throws NullPointerException if the text is <code>null</code>
	 */
	public static void isEmpty(final String text) {
		isEmpty(text, "the text is not empty");
	}

	/**
	 * check the {@link String} of is empty. if the {@link String} is not empty, then <code>throw new {@link IllegalArgumentException}</code> with the
	 * message.
	 * 
	 * @param text the {@link String} to check of is empty
	 * @param message the message of the {@link IllegalArgumentException}
	 * @throws IllegalArgumentException if the {@link String} is not empty
	 * @throws NullPointerException if the text is <code>null</code>
	 */
	public static void isEmpty(final String text, final String message) {
		if (!text.isEmpty()) {
			throw new IllegalArgumentException(message);
		}
	}

	/**
	 * If the text does not has length, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param text the value to check
	 * @param length the length to check
	 * @throws IllegalArgumentException
	 */
	public static void hasLength(final String text, final long length) {
		hasLength(text, length, String.format("'%s' does not has length '%d'.", text, length));
	}

	/**
	 * If the text does not has length, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param text the value to check
	 * @param length the length to check
	 * @param message the throwing message
	 * @throws IllegalArgumentException
	 */
	public static void hasLength(final String text, final long length, final String message) {
		Assert.isTrue(text.length() == length, message);
	}

}
